package com.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.dao.UploadDao;
import com.pojo.Image;
import com.service.UploadService;
import com.util.JdbcUtils;

public class UploadServiceImpl implements UploadService {

	private UploadDao uploadDao = new UploadDao();

	
	@Override
	public int saveImage(Map<String,String> image) {
		int i = 0;
		try {
			JdbcUtils.begin();
			i = uploadDao.saveImage(image);
		} catch (SQLException e) {
			
			e.printStackTrace();
			JdbcUtils.rollback();
			return 0;
		}finally{
			JdbcUtils.commit();
		}
		return i;
	}


	@Override
	public List<Image> getImage() {
		List<Image> imageList = null;
		try {
			JdbcUtils.begin();
			imageList = uploadDao.getImage();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			JdbcUtils.rollback();
			return null;
		}finally{
			JdbcUtils.commit();
		}
		return imageList;
	}


	@Override
	public String selectImageByName(String name) {
		String pictureFile = null;
		try {
			JdbcUtils.begin();
			pictureFile = uploadDao.selectImageByName(name);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			JdbcUtils.rollback();
			return null;
		}
		finally{
			JdbcUtils.commit();
		}
		return pictureFile;
	}


}
